﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using ERMap;

namespace PhoneBook.Manage
{
    public class LoginLog
    {
        public static DataSet listloginlog(long usertype, string username, DateTime starttime, DateTime endtime)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select loginlog.*,sys_users.usertype,sys_users.username from LoginLog left join sys_users on loginlog.userid=sys_users.userid");
            sb.Append(" where loginlog.usertype=@usertype and (sys_users.username like @username or loginlog.loginid  like @username) and logintime between @starttime and @endtime");
            sb.Append("  order by logintime desc ");

            Hashtable param = new Hashtable();
            param["usertype"] = usertype;
            param["username"] = "%" + username + "%";
            param["starttime"] = starttime;
            param["endtime"] = endtime;

            return ERMapHelper.getCustomData(sb.ToString(), param);
        }

        public static void add(Hashtable newloginlog)
        {
            
            ERMapHelper.setmodel("LoginLog", "LoginLogId", newloginlog);
        }

        public static DataSet listgroupsubtotal()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select groupid,groupname,SUM(1)as subtotal from( ");
            sb.Append("select g.groupid,g.groupname,c.employeeid from b_group g inner join  ");
            sb.Append("(select d.departmentid,d.groupid,e.employeeid from b_department d inner join b_employee e on  ");
            sb.Append("d.departmentid=e.departmentid)c ");
            sb.Append("on g.groupid=c.groupid ");
            sb.Append(")cc group by groupid,groupname ");
            return ERMapHelper.getCustomData(sb.ToString(), null);
        }

    }
}
